package com.itheima.test8;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

/**
 * @Author:gy
 * @Date: 2025/09/03 17:26
 * @Description:
 */
public class ServerDemo {
    public static void main(String[] args) throws Exception {
        //创建一个码头
        DatagramSocket ds = new DatagramSocket(10001);
        while (true) {
            //找一个新箱子去打包礼物
            byte [] bytes = new byte[1024];
            DatagramPacket dp = new DatagramPacket(bytes, bytes.length);
            ds.receive(dp);
            //解析详细
            byte[] data = dp.getData();
            int length = dp.getLength();
            System.out.println(new String(data, 0, length));
        }
        //ds.close();
    }
}
